/*
 * @Author: Wanko
 * @Date: 2024-06-16 09:27:57
 * @LastEditors: Wanko
 * @LastEditTime: 2024-06-18 10:16:40
 * @Description: 
 */

const mongoose = require('mongoose')
const { Schema, model } = mongoose
const dayjs = require('dayjs')

const cardSchema = new Schema({
  __v: Number,
  id: { type: String, unique: true },
  owner: {
    type: Schema.Types.ObjectId,
    ref: 'User',
    required: true,
  },
  content: String,
  // 创建时间
  createTime: {
    type: String,
    default: () => dayjs().format('YYYY-MM-DD HH:mm:ss')
  },
  updateTime: {
    type: String
  },
  // 标签
  tags: [String],
  flomo_slug: String,
  like_count: Number,
  // 是否置顶
  is_top: {
    type: Boolean,
    default: false
  },

  like_count: {
    type: Number,
    default: 0
  },

  collection_count: {
    type: Number,
    default: 0
  },

  comment_count: {
    type: Number,
    default: 0
  },

  relationship: { type: Object, default: {} }
})

// 在保存文档之前，将 id 字段设置为 _id 的值
cardSchema.pre('save', function (next) {
  this.id = this._id.toString()
  next()
})

module.exports = model('Card', cardSchema)